package com.wenhuang.chatgptopen.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wenhuang.chatgptopen.pojo.Fans;
import com.wenhuang.chatgptopen.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/*
 *@Time：2023/6/3
 *@Author：Jelly
 */
public interface FansMapper extends BaseMapper<Fans> {

    //获取好友列表
    @Select("select * from user,(select fans_id from fans where user_id = #{userId}) as temp " +
            "where id = temp.fans_id")
    List<User> getFans(Fans fans);

    //通过userId和FansId向数据库添加粉丝关联
    @Insert("insert into fans values (null,#{userId},#{fansId},#{createTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    Integer addFans(Fans fans);

    //通过userId和FansId向数据库删除粉丝关联
    @Delete("delete from fans where user_id = #{userId} and fans_id = #{fansId}")
    Integer deleteFans(Fans fans);

    //通过userId和fansId查询是否关注
    @Select("select * from fans where user_id = #{userId} and fans_id = #{fansId}")
    Integer getFollowed(Fans fans);

}
